const app = getApp()
Component({
  lifetimes: {
    ready() {
      //订阅购物车变动事件 TODO
      this.setData({
        myShoppingCart:getApp().globalData.shopCart
      })
      const _this = this
      app.eventShopBus.on("update", (shopCart) => {
        _this.setData({
          myShoppingCart: shopCart
        })
      })
    }
  },
  properties: {
    couponCount: {
      type: Number,
      value: 0
    },
    coupons: {
      type: Array,
      value: []
    }
  },

  data: {
    showCouponPopup: false,
    myShoppingCart:{},
    coupons:[{
      id:1,
      couponType:1,
      couponType:"couponType",
      name:"name"
    }]
  },

  methods: {
    onCouponClick() {
      this.setData({
        showCouponPopup: true
      });
    },

    hideCoupons() {
      this.setData({
        showCouponPopup: false
      });
    },

    onCheckout() {//去结算
      if (this.data.totalCount === 0) return;
      this.triggerEvent('checkout', {
        amount: this.data.totalAmount,
        count: this.data.totalCount
      });
    }
  }
});